- Geospatial: when your data contains geographical coordinates of interest
- Trends, clusters, and patterns can be found in spatial data analysis leading to a greater understanding of current events and ability to predict future events
February 11, 2018
ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame())
geom_polygon(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
setwd("C:/Users/Tom Kennon/Documents/UCONN/STAT 6494/Presentation")
library(maps)
library(ggplot2)
states <- map_data("state")
pop <- read.csv("state populations.csv")
colnames(states)[5] <- "State"
pop$State <- sapply(pop$State, tolower)
pop$Population <- as.numeric(pop$Population)
choro <- merge(states, pop, sort=FALSE, by="State") choro <- choro[order(choro$order),]
ggplot(choro, aes(long, lat))
ggplot(choro, aes(long, lat)) + geom_polygon(aes(group = group, fill=Population))
ggplot(choro, aes(long, lat)) +
geom_polygon(aes(group = group, fill=Population)) +
scale_fill_gradientn(name="Population Size",
colours = c("magenta1", "magenta4"))
ggplot(choro, aes(long, lat)) +
geom_polygon(aes(group = group, fill=Population)) +
scale_fill_gradientn(name="Population Size",
colours = c("magenta1", "magenta4")) +
labs(title = "Geographical Heat Map of Population Size",
x = "Longitude", y = "Latitude")
ggplot(choro, aes(long, lat)) +
geom_polygon(aes(group = group, fill=Population)) +
scale_fill_gradientn(name="Population Size",
colours = c("magenta1", "magenta4")) +
labs(title = "Geographical Heat Map of Population Size",
x = "Longitude", y = "Latitude") +
coord_map("albers", at0 = 45.5, lat1=29.5)
ggmap(ggmap, extent = "panel", base_layer, maprange = FALSE, legend = "right", padding = 0.02, darken = c(0, "black"), ...)
sat <- read.csv("scores.csv")
sat <- sat[is.na(sat$Average.Score..SAT.Math.) == FALSE,]
sat <- sat[is.na(sat$Average.Score..SAT.Reading.) == FALSE,]
sat <- sat[is.na(sat$Average.Score..SAT.Writing.) == FALSE,]
sat$Raw.Score <- sat$Average.Score..SAT.Math. +
sat$Average.Score..SAT.Reading. + sat$Average.Score..SAT.Writing.
library(maps)
library(ggplot2)
library(ggmap)
library(leaflet)
nyc <- get_map(location = c(lat = 40.71, lon = -74.00), zoom = 11)
## note : locations should be specified in the lon/lat format, not lat/lon.
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.71,-74&zoom=11&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
nyc_sat <- ggmap(nyc) nyc_sat
nyc_sat <- ggmap(nyc) + geom_point(data = sat, aes(x = Longitude, y = Latitude)) nyc_sat
nyc_sat <- ggmap(nyc) +
geom_point(data = sat, aes(x = Longitude, y = Latitude,
size=Raw.Score))
nyc_sat
nyc_sat <- ggmap(nyc) +
geom_point(data = sat, aes(x = Longitude, y = Latitude,
size=Raw.Score)) +
scale_size(range = c(0, 5))
nyc_sat
nyc_sat <- ggmap(nyc) +
geom_point(data = sat, aes(x = Longitude, y = Latitude,
size=Raw.Score,
alpha=0.10),shape=21) +
scale_size(range = c(0, 5))
nyc_sat
nyc_sat <- ggmap(nyc) +
geom_point(data = sat, aes(x = Longitude, y = Latitude,
size=Raw.Score, alpha=0.10),shape=21) +
scale_size(range = c(0, 5)) +
scale_alpha(guide = 'none') +
labs(title = "SAT Scores in New York City High Schools",
x = "Longitude", y = "Latitude", size = "SAT Score")
nyc_sat
m <- leaflet(sat) %>% addTiles()
m <- leaflet(sat) %>% addTiles()
m %>% addCircleMarkers(lat = ~Latitude, lng = ~Longitude,
fill = TRUE, radius = ~(1/150 * Raw.Score), color="black")
m <- leaflet(sat) %>% addTiles()
m %>% addCircleMarkers(lat = ~Latitude, lng = ~Longitude,
fill = TRUE, radius = ~(1/150 * Raw.Score), color="black",
clusterOptions = markerClusterOptions())